<#-- 接口实现类生成模板 -->
package ${packageName};
<#list importPackage as importPackage>
import ${importPackage};
</#list>
/**
 * <p>${classDesc}</p>
 * @author ${userName}
 * @since ${currentDate}
 */
<#if annotations ??>
<#list annotations as annotation>
@${annotation}
</#list>
<#else>
</#if>
public class ${className}<#if extendsClass ??> extends ${extendsClass} <#else> </#if><#if baseInterfaceName ??> implements ${baseInterfaceName} <#else> </#if>{

    <#list mapperRelations as mapperRelation>
    <#if mapperRelation.columnComment ??>
    /**
     * ${mapperRelation.columnComment}
     */
    </#if>
	<#if mapperRelation.annotation ??>
    @${mapperRelation.annotation }
    </#if>
    private ${mapperRelation.propertyType} ${mapperRelation.property};<#if mapperRelation_has_next> ${"\n"} </#if>
    </#list>

    @Override
    public ${meta}DTO add(${meta}DTO ${meta?uncap_first}DTO){
      ${meta}DO ${meta?uncap_first}DO = toDO(${meta?uncap_first}DTO);
      ${meta?uncap_first}DO.setValiFlag("1");
      ${injectClass?uncap_first}.insert(${meta?uncap_first}DO);
      return toDTO(${meta?uncap_first}DO);
    }

    @Override
    public Boolean delete(String id){
      ${meta}DO ${meta?uncap_first}DO = new ${meta}DO();
      ${meta?uncap_first}DO.set${primaryKeyProperty}(id);
      ${meta?uncap_first}DO.setValiFlag("0");
      return ${injectClass?uncap_first}.updateById(${meta?uncap_first}DO)>0;
    }

    @Override
    public ${meta}DTO update(${meta}DTO ${meta?uncap_first}DTO){
      ${meta}DO ${meta?uncap_first}DO = toDO(${meta?uncap_first}DTO);
      ${injectClass?uncap_first}.updateById(${meta?uncap_first}DO);
      return toDTO(${meta?uncap_first}DO);
    }

    @Override
    public ${meta}DTO get(String id){
      return toDTO(${injectClass?uncap_first}.selectById(id));
    }

    @Override
    public PageResultData<${meta}DTO> getPage(int pageNo, int pageSize, ${meta}DTO ${meta?uncap_first}DTO){
      Page<${meta}DO> page = PageFactory.createPage(pageNo, pageSize);
      ${meta}DO ${meta?uncap_first}DO = toDO(${meta?uncap_first}DTO);
      QueryWrapper<${meta}DO> queryWrapper = new QueryWrapper<${meta}DO>();
      <#list contitions as contition>
      <#if contition.propertyType=="Date">
      if (null!=${meta?uncap_first}DO.get${contition.property?cap_first}() ){
        queryWrapper.like("${contition.column}", ${meta?uncap_first}DO.get${contition.property?cap_first}());
      }
      <#else>
      if (!StringUtils.isEmpty(${meta?uncap_first}DO.get${contition.property?cap_first}()) ){
        queryWrapper.like("${contition.column}", ${meta?uncap_first}DO.get${contition.property?cap_first}());
      }
      </#if>
      </#list>
      queryWrapper.eq("VALI_FLAG","1");
      queryWrapper.orderByAsc("${primaryKey}");
      page = ${injectClass?uncap_first}.selectPage(page, queryWrapper);
      // do list --> dto list
      List<${meta}DO> records = page.getRecords();
      List<${meta}DTO> list = new ArrayList<${meta}DTO>();
      for (${meta}DO row : records) {
        list.add(toDTO(row));
      }
      PageResultData<${meta}DTO> result = PageFactory.createPage(list, page);
      return result;
    }

    private ${meta}DO toDO(${meta}DTO ${meta?uncap_first}DTO){
      ${meta}DO ${meta?uncap_first}DO = ${meta?uncap_first}DTOConverter.convertTo${meta}DO(${meta?uncap_first}DTO);
      return ${meta?uncap_first}DO;
    }

    private ${meta}DTO toDTO(${meta}DO ${meta?uncap_first}DO){
      ${meta}DTO ${meta?uncap_first}DTO = ${meta?uncap_first}DTOConverter.convertTo${meta}DTO(${meta?uncap_first}DO);
      return ${meta?uncap_first}DTO;
    }
}